package com.sali.config;

import com.sali.entity.UploadLocalProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableConfigurationProperties(UploadLocalProperties.class)
public class WebMvcCongfiguration implements WebMvcConfigurer {

    @Autowired
    private UploadLocalProperties uploadLocalProperties;

    // 这个就是springboot中springMvc让程序开发者去配置文件上传的额外的静态资源服务的配置
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler(uploadLocalProperties.getStaticPatternPath())
                .addResourceLocations("file:" + uploadLocalProperties.getUploadFolder());
    }

}
